<?php
/*
 * @Author: CYH
 * @Date: 2020-10-31 10:25:06
 * @LastEditTime: 2021-05-10 09:36:36
 * @LastEditors: Please set LastEditors
 * @Description: 入住管理model类
 * @FilePath: \application\models\Register\Check_in.php
 */
    //入住管理model类 
    class Check_in extends CI_Model
    {
        //构造方法
        public function __construct()
        {

            parent::__construct();
            $this->load->database();
        }
        // public function erp_connect($RY_name)
        // {
        //     if ($RY_name == '') {
        //         $return = array('res' => '40002', 'msg' => '请输入必填字段');
        //         $result = json_encode($return);
        //     } else {
        //         //调用U8接口获取人员数据
        //         $serverName = "192.168.10.20"; //服务器地址
        //         $username = "dorm"; //数据库用户名
        //         $password = "123456"; //数据库密码
        //         $connectionInfo = array("UID" => $username, "PWD" => $password, "Database" => "UFDATA_666_2017");
        //         $conn = sqlsrv_connect($serverName, $connectionInfo);
        //         if ($conn) {
        //             $sj1 = " cPsn_Name = '" . $RY_name . "'";
        //             // $sql = 'SELECT * FROM hr_hi_person a inner join Department b ON a.cDept_num = b.cDepCode WHERE' ."$sj1";
        //             $sql = 'SELECT A.JobNumber ,A.vIDNo ,A.rSex ,A.rNativePlace ,A.rPerResidence FROM hr_hi_person AS A WHERE' . $sj1;
        //             $query = iconv("UTF-8", "GB2312//IGNORE", $sql);
        //             $params = array();
        //             $options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
        //             $return = sqlsrv_query($conn, $query, $params, $options);  //$conn资源句柄
        //             if ($return == true) {
        //                 if ($row = sqlsrv_fetch_array($return, SQLSRV_FETCH_ASSOC)) {
        //                     $num = iconv("GB2312", "UTF-8//IGNORE", $row['JobNumber']);
        //                     $vid = iconv("GB2312", "UTF-8//IGNORE", $row['vIDNo']);
        //                     $Sex = iconv("GB2312", "UTF-8//IGNORE", $row['rSex']);
        //                     // $rNa = iconv("GB2312", "UTF-8//IGNORE",$row['rNativePlace']);
        //                     $rPe = iconv("GB2312", "UTF-8//IGNORE", $row['rPerResidence']);
        //                     $rNa = substr($vid, 0, 6);
        //                     $this->db->select('hometown_description');
        //                     $this->db->where('hometown_number', $rNa);
        //                     $home_town = $this->db->get('dorm_hometown');
        //                     if ($home_town->num_rows() == 0) {
        //                         $return_fa = array('res' => '40000', 'msg' => '此人所属籍贯区域编号已撤销或在系统中不存在请手动录入', 'data' => array('SQ_RY_number' => $num, 'SQ_RY_idcardnum' => $vid, 'SQ_RY_sex' => $Sex));
        //                         $result = json_encode($return_fa);
        //                     } else {
        //                         $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => array('SQ_RY_number' => $num, 'SQ_RY_idcardnum' => $vid, 'SQ_RY_sex' => $Sex, 'SQ_RY_address' => $rPe, 'SQ_RY_location' => $home_town->row()->hometown_description));
        //                         $result = json_encode($return_su);
        //                     }
        //                 } else {
        //                     $return_fa = array('res' => '40000', 'msg' => 'ERP无此人员记录', 'data' => '');
        //                     $result = json_encode($return_fa);
        //                 }
        //             } else {
        //                 $return_fa = array('res' => '40001', 'msg' => '请检查sqlsrv_query参数', 'data' => $return);
        //                 $result = json_encode($return_fa);
        //             }
        //             return $result;
        //         } else {
        //             echo "连接失败！";
        //             $error = eval('return ' . iconv("gbk", "utf-8", var_export(sqlsrv_errors(), true) . ';'));
        //             var_dump($error);
        //             exit;
        //         }
        //     }
        // }
        
        /**
         * @description: 入住申请人员查询
         * @param {name, idNumber, limit}
         * @return {*}
         */        
        public function check_in_people_select($name, $idNumber, $limit)
        {
            if($limit != '')
            {
                $limit1 = ("$limit" - 1) * 10;
            }
            $sj1 = $name == '' ? ' 1 = 1 ':" name LIKE '%".$name."%'";
            $sj2 = $idNumber  == '' ? ' AND 1 = 1 ':" AND idNumber LIKE '%".$idNumber."%'";
            $sj3 = $limit == '' ? ' AND 1 = 1 ' : " Limit " . $limit1 . ",10";
            if($limit != '')
            {
                $sql = "SELECT address ,sex ,department ,job ,phone ,name ,idNumber ,room_number FROM dorm_stay_retreat_tune WHERE".$sj1 .$sj2 .$sj3;
                $query = $this->db->query($sql ,$sj1 ,$sj2 ,$sj3);
                $return = $this->db->affected_rows();
            }
            else
            {
                $sql = "SELECT address ,sex ,department ,job ,phone ,name ,idNumber ,room_number FROM dorm_stay_retreat_tune WHERE".$sj1 .$sj2;
                $query = $this->db->query($sql ,$sj1 ,$sj2);
                $return = $this->db->affected_rows();
            }
            if($return)
            {
                $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $query->result());
                $result = json_encode($return_su);
            } 
            else 
            {
                $return_fa = array('res' => '40001', 'msg' =>'查询无数据', 'data' => '');
                $result = json_encode($return_fa);
            }
            return $result;
        }

        /*入住进行步骤
        1.申请人申请
        (1)数据插入记录表
        2.宿管员信息录入
        (1)更新记录表
        */

        /**
         * @description: 入住方法：申请人节点-临时入住
         * @param {name, sex, idNumber, address, phone, emergencyContact, relationShip, emergencyPhone, department, job, jobNumber, temporary}
         * @return {*}
         */        
        public function check_in_temporary($name, $sex, $idNumber, $address, $phone, $emergencyContact, $relationShip, $emergencyPhone, $department, $job, $jobNumber, $temporary)
        {
            //记录表数据插入
            $data_stay_retreat_tune = array(
                'name' => $name,                            //姓名
                'sex' => $sex,                              //性别
                'idNumber' => $idNumber,                    //身份证号
                'address' => $address,                      //户籍地址
                'emergencyContact' => $emergencyContact,    //紧急联系人
                'phone' => $phone,                          //联系方式
                'applyName' => $name,                       //姓名
                'apply_date' => date("Y-m-d"),              //申请日期
                'type' => 1                                 //类别
                );
                $this->db->insert('dorm_stay_retreat_tune' ,$data_stay_retreat_tune);
                $result_checkin = $this->db->affected_rows();
                return $result_checkin;
            }
        
        //入住方法：申请人节点-非临时入住
        public function check_in_ntemporary($name, $sex, $idNumber, $address, $phone, $emergencyContact, $relationShip, $emergencyPhone, $department, $job, $jobNumber, $temporary)
        {
            //记录表数据插入
            $data_stay_retreat_tune = array(
                'name' => $name,
                'sex' => $sex,
                'idNumber' => $idNumber,
                'address' => $address,
                'address' => $address,
                'phone' => $phone,
                'emergencyContact' => $emergencyContact,
                'relationShip' => $relationShip,
                'emergencyPhone' => $emergencyPhone,
                'department' => $department,
                'job' => $job,
                'jobNumber' => $jobNumber,
                'applyName' => $name,
                'apply_date' => date("Y-m-d"),
                'type' => 1
            );
            $this->db->insert('dorm_stay_retreat_tune' ,$data_stay_retreat_tune);
            $result_checkin = $this->db->affected_rows();
            return $result_checkin;
        }
        
        /**
         * @description:入住方法：申请人节点 
         * @param {name, sex, idNumber, address, phone, emergencyContact, relationShip, emergencyPhone, department, job, jobNumber, temporary}
         * @return {*}
         */
        public function check_in_applicant($name, $sex, $idNumber, $address, $phone, $emergencyContact, $relationShip, $emergencyPhone, $department, $job, $jobNumber, $temporary)
        {
            //临时入住
            if($temporary == 1)
            {
                if($name == '' || $idNumber == '' || $sex == '' || $address == '')
                {
                    $return = array('res' => '40002', 'msg' => '请输入必填字段', 'data' => '');
                    $result = json_encode($return);
                } 
                else 
                {
                    //调用临时入住方法
                    $result_checkin = $this->Check_in->check_in_temporary($name, $sex, $idNumber, $address, $phone, $emergencyContact, $relationShip, $emergencyPhone, $department, $job, $jobNumber, $temporary);

                    if($result_checkin)
                    {
                        $return_su = array('res' => '40000', 'msg' => '申请成功', 'data' => $name);
                        $result = json_encode($return_su);
                    } 
                    else 
                    {
                        $return_fa = array('res' => '40001', 'msg' =>'申请失败', 'data' => '');
                        $result = json_encode($return_fa);
                    }
                }

            //非临时入住    
            } 
            else 
            {
                if($name == '' || $sex == '' || $idNumber == '' || $address == '' || $phone == '' || $emergencyContact == '' || $relationShip == '' || $emergencyPhone == '' || $department == '' || $job == '')
                {
                    $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
                    $result = json_encode($return);
                } 
                else 
                {
                    $query = $this->db->get_where('dorm_stay_retreat_tune' ,array('idNumber' => $idNumber, 'area_number' => '', 'floor_number' => '', 'dorm_floor' => '', 'room_number' => ''));
                    if($query->num_rows()>0){
                        $return = array('res' => '40002', 'msg' => '已申请，不允许重复申请' ,'data' => '');
                        $result = json_encode($return);
                    } 
                    else 
                    {
                        //调用临时入住方法
                        $result_checkin = $this->Check_in->check_in_ntemporary($name, $sex, $idNumber, $address, $phone, $emergencyContact, $relationShip, $emergencyPhone, $department, $job, $jobNumber, $temporary);
                        if($result_checkin)
                        {
                            $return_su = array('res' => '40000', 'msg' => '申请成功', 'data' => $name);
                            $result = json_encode($return_su);
                        } 
                        else 
                        {
                            $return_fa = array('res' => '40001', 'msg' =>'申请失败', 'data' => '');
                            $result = json_encode($return_fa);
                        }
                    }
                }
            }
            return $result;
        }

        /**
         * @description: 记录表更新
         * @param {idNumber, area_number, floor_number, dorm_floor, room_number, bedNumber, liveDate, name, department_2, department_3, sex, phone, location, company, temporaryJobNumber}
         * @return {*}
         */        
        public function update_recording($idNumber = FALSE, $jobNumber = FALSE, $job = FALSE, $area_number = FALSE, $floor_number = FALSE, $dorm_floor = FALSE, $room_number = FALSE, $bedNumber = FALSE, $liveDate = FALSE, $name = FALSE, $department_2 = FALSE, $department_3 = FALSE, $sex = FALSE, $phone = FALSE, $location = FALSE, $company = FALSE, $temporaryJobNumber = FALSE)
        {
            if($company == '0')
            {
                //将数据插入到入住/退宿/调宿表
                $data_stay_retreat_tune = array(
                    'area_number' => $area_number,      //区域编号
                    'floor_number' => $floor_number,    //宿舍楼编号
                    'dorm_floor' => $dorm_floor,        //宿舍楼层号
                    'room_number' => $room_number,      //宿舍房间号
                    'idNumber' => $idNumber,            //身份证号
                    'name' => $name,                    //姓名
                    'jobNumber' => $jobNumber,          //工号
                    'job' => $job,                      //岗位
                    'department2' => $department_2,     //二级部门
                    'department3' => $department_3,     //三级部门
                    'sex' => $sex,                      //性别
                    'phone' => $phone,                  //联系方式
                    'location' => $location,            //籍贯
                    'bedNumber' => $bedNumber,          //床位号
                    'liveDate' => $liveDate,            //入住日期
                    'type' => '1'                       //类别
                );
            }
            elseif($company == '1')
            {
                //将数据插入到入住/退宿/调宿表
                $data_stay_retreat_tune = array(
                    'area_number' => $area_number,      //区域编号
                    'floor_number' => $floor_number,    //宿舍楼编号
                    'dorm_floor' => $dorm_floor,        //宿舍楼层号
                    'room_number' => $room_number,      //宿舍房间号
                    'idNumber' => $idNumber,            //身份证号
                    'jobNumber' => $temporaryJobNumber, //工号
                    'name' => $name,                    //姓名
                    'department2' => $department_2,     //二级部门
                    'department3' => $department_3,     //三级部门
                    'sex' => $sex,                      //性别
                    'phone' => $phone,                  //联系方式
                    'location' => $location,            //籍贯
                    'bedNumber' => $bedNumber,          //床位号
                    'liveDate' => $liveDate,            //入住日期
                    'type' => '1'                       //类别
                );
            }

            $this->db->insert('dorm_stay_retreat_tune' ,$data_stay_retreat_tune);
            $query_stay_retreat_tune = $this->db->affected_rows();
            return $query_stay_retreat_tune;
        }

        /**
         * @description: 人员信息表数据插入
         * @param {area_number, floor_number, dorm_floor, room_number, check_inAddress, name, jobNumber, degsonid, idNumber, sex, department, job, location, phone, emergencyContact, relationShip, emergencyPhone, liveDate, bedNumber, remarks}
         * @return {*}
         */        
        // public function add_livepeople($area_number = FALSE, $floor_number = FALSE, $dorm_floor = FALSE, $room_number = FALSE, $check_in_address = FALSE, $name = FALSE, $idNumber = FALSE, $sex = FALSE, $department = FALSE, $location = FALSE, $phone = FALSE, $liveDate = FALSE, $bedNumber = FALSE, $remarks = FALSE, $company = FALSE, $temporaryJobNumber = FALSE)
        public function add_livepeople($area_number = FALSE, $floor_number = FALSE, $dorm_floor = FALSE, $room_number = FALSE, $check_in_address = FALSE, $name = FALSE, $idNumber = FALSE, $jobNumber = FALSE, $sex = FALSE, $department_2 = FALSE, $department_3 = FALSE, $job = FALSE, $location = FALSE, $phone = FALSE, $liveDate = FALSE, $bedNumber = FALSE, $remarks = FALSE, $company = FALSE, $temporaryJobNumber = FALSE)
        { 
            $repetitionCheck  = 0; 
            //判断人员是否重复入住
            $repetition = $this->db->get_where('dorm_livepeople',array('idNumber' => $idNumber));
            if($repetition->num_rows()>0)
            {
                $repetitionCheck = 'X';
            }

            if($company == '0')
            {
                $data_livepeople = array(
                    'area_number' => $area_number,                              //区域编号
                    'floor_number' => $floor_number,                            //宿舍楼编号
                    'dorm_floor' => $dorm_floor,                                //宿舍楼层号
                    'room_number' => $room_number,                              //宿舍房间号
                    'check_inAddress' => $check_in_address,                     //入住位置
                    'name' => $name,                                            //人员姓名
                    'idNumber' => $idNumber,                                    //身份证号
                    'jobNumber' => $jobNumber,                                  //工号
                    'sex' => $sex,                                              //性别
                    // 'department' => $department,                             //部门
                    'department2' => $department_2,                             //二级部门
                    'department3' => $department_3,                             //三级部门
                    'job' => $job,                                              //岗位
                    'location' => $location,                                    //籍贯
                    'phone' => $phone,                                          //联系电话
                    'repetitionCheck' => $repetitionCheck,                      //是否重复入住 
                    // 'emergencyContact' => $emergencyContact,                 //紧急联系人
                    // 'relationShip' => $relationShip,                         //与紧急联系人关系
                    // 'emergencyPhone' => $emergencyPhone,                     //紧急联系人电话
                    'liveCheck' => 'X',                                         //是否入住
                    'liveDate' => $liveDate,                                    //入住日期
                    'bedNumber' => $bedNumber,                                  //床位号
                    'remarks' => $remarks                                       //备注
                );
            }
            elseif($company == '1')
            {
                $data_livepeople = array(
                    'area_number' => $area_number,                              //区域编号
                    'floor_number' => $floor_number,                            //宿舍楼编号
                    'dorm_floor' => $dorm_floor,                                //宿舍楼层号
                    'room_number' => $room_number,                              //宿舍房间号
                    'check_inAddress' => $check_in_address,                     //入住位置
                    'name' => $name,                                            //人员姓名
                    'idNumber' => $idNumber,                                    //身份证号
                    'jobNumber' => $temporaryJobNumber,                         //工号
                    'sex' => $sex,                                              //性别
                    // 'department' => $department,                             //部门
                    'department2' => $department_2,                             //二级部门
                    'department3' => $department_3,                             //三级部门
                    // 'job' => $job,                                           //岗位
                    'location' => $location,                                    //籍贯
                    'phone' => $phone,                                          //联系电话
                    'repetitionCheck' => $repetitionCheck,                      //是否重复入住 
                    // 'emergencyContact' => $emergencyContact,                 //紧急联系人
                    // 'relationShip' => $relationShip,                         //与紧急联系人关系
                    // 'emergencyPhone' => $emergencyPhone,                     //紧急联系人电话
                    'liveCheck' => 'X',                                         //是否入住
                    'liveDate' => $liveDate,                                    //入住日期
                    'bedNumber' => $bedNumber,                                  //床位号
                    'remarks' => $remarks                                       //备注
                );
            }

            //将人员信息插入到人员信息表中
            $this->db->insert('dorm_livepeople' ,$data_livepeople);
            $query_livepeople = $this->db->affected_rows();
            return $query_livepeople;
        }

        /**
         * @description: 床位信息写入
         * @param {area_number, floor_number, dorm_floor, room_number, idNumber, jobNumber, name, sex, department, phone, bedNumber, remarks}
         * @return {*}
         */        
        // public function add_bed($area_number = FALSE, $floor_number = FALSE, $dorm_floor = FALSE, $room_number = FALSE, $idNumber = FALSE, $name = FALSE, $sex = FALSE, $department = FALSE, $phone = FALSE, $bedNumber = FALSE, $remarks = FALSE, $company = FALSE, $temporaryJobNumber = FALSE)
        // {
        public function add_bed($area_number = FALSE, $floor_number = FALSE, $dorm_floor = FALSE, $room_number = FALSE, $idNumber = FALSE, $jobNumber = FALSE, $name = FALSE, $sex = FALSE, $department_2 = FALSE, $department_3 = FALSE, $job = FALSE, $phone = FALSE, $bedNumber = FALSE, $remarks = FALSE, $company = FALSE, $temporaryJobNumber = FALSE)
        {
            if($company == '0')
            {
                $data_bed = array(
                    'idNumber' => $idNumber,                                    //身份证号
                    'jobNumber' => $jobNumber,                                  //工号                  
                    'name' => $name,                                            //人员姓名
                    'sex' => $sex,                                              //性别
                    // 'department' => $department,                             //部门
                    'department2' => $department_2,                             //二级部门
                    'department3' => $department_3,                             //三级部门
                    'job' => $job,                                              //岗位
                    'phone' => $phone,                                          //联系电话
                    'bedStatus' => 1,                                           //床位状态
                    'check_inWhether' => 1,                                     //床位是否住人
                    'bedNumber' => $bedNumber,                                  //床位号
                    'remarks' => $remarks                                       //备注
                );
            }
            elseif($company == '1')
            {
                $data_bed = array(
                    'idNumber' => $idNumber,                                    //身份证号
                    'jobNumber' => $temporaryJobNumber,                         //工号
                    'name' => $name,                                            //人员姓名
                    'sex' => $sex,                                              //性别
                    // 'department' => $department,                             //部门
                    'department2' => $department_2,                             //二级部门
                    'department3' => $department_3,                             //三级部门
                    'phone' => $phone,                                          //联系电话
                    'bedStatus' => 1,                                           //床位状态
                    'check_inWhether' => 1,                                     //床位是否住人
                    'bedNumber' => $bedNumber,                                  //床位号
                    'remarks' => $remarks                                       //备注
                );
            }
            //将人员信息更新到床位表中
            $where_bed = array('area_number' => $area_number ,'floor_number' => $floor_number ,'room_number' => $room_number ,'bedNumber' => $bedNumber);
            $this->db->where($where_bed);
            $this->db->update('dorm_bed' ,$data_bed);
            $query_bed = $this->db->affected_rows();
            return $query_bed;
        }

        /**
         * @description: 水电信息写入
         * @param {area_number,floor_number,room_number,name,jobNumber,liveDate}
         * @return {*}
         */        
        // public function add_manday($area_number, $floor_number, $room_number, $name, $jobNumber, $liveDate)
        // {
        //     if($jobNumber != '')
        //     {
        //         $data_manday = array(
        //             'area_number' => $area_number,                              //区域编号
        //             'floor_number' => $floor_number,                            //宿舍楼编号
        //             'room_number' => $room_number,                              //宿舍房间号
        //             'name' => $name,                                            //人员姓名
        //             'jobNumber' => $jobNumber,                                  //工号
        //             'dorm_livedate' => $liveDate,                               //宿舍入住日期
        //             'room_livedate' => $liveDate                                //房间入住日期
        //         );
        //     }
        //     //若工号为空则不更新工号
        //     else
        //     {
        //         $data_manday = array(
        //             'area_number' => $area_number,                              //区域编号
        //             'floor_number' => $floor_number,                            //宿舍楼编号
        //             'room_number' => $room_number,                              //宿舍房间号
        //             'name' => $name,                                            //人员姓名
        //             'jobNumber' => $jobNumber,                                  //工号
        //             'dorm_livedate' => $liveDate,                               //宿舍入住日期
        //             'room_livedate' => $liveDate                                //房间入住日期
        //         );
        //     }
        //     //将数据更新到水电表中
        //     $this->db->insert('dorm_manday_calc' ,$data_manday);
        //     $query_manday = $this->db->affected_rows();
        //     return $query_manday;
        // }

        public function temporaryEmployee()
        {
            $query = $this->db->query("SELECT * FROM dorm_temporaryemployee_record ORDER BY jobNumber DESC");
            if ($query->result()) 
            {
                $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $query->result());
                $result = json_encode($return_su);
            } 
            else 
            {
                $return_fa = array('res' => '40001', 'msg' => '查询无数据', 'data' => '');
                $result = json_encode($return_fa);
            }
            return $result;
        }

        /**
         * @description: 入住方法:宿管员节点
         * @param {name, idNumber, liveDate, area_number, floor_number, dorm_floor, room_number, bedNumber, sex, location, phone, department_2, department_3, company, remarks}
         * @return {*}
         */        
        public function check_in_admin($name, $idNumber, $jobNumber ,$job ,$liveDate, $area_number, $floor_number, $dorm_floor, $room_number, $bedNumber, $sex, $location, $phone, $department_2, $department_3, $company, $remarks)
        {
            if($company == 0)
            {
                // if ( $name == '' || $idNumber == '' || $liveDate == '' || $area_number == '' || $floor_number == '' || $dorm_floor == '' || $room_number == '' || $bedNumber == '' || $location == '' || $phone == '' || $department == '') 
                // {
                //     $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
                //     $result = json_encode($return);
                // } 
                // if ( empty($name) || empty($idNumber) || empty($liveDate) || empty($area_number) || empty($floor_number) || empty($dorm_floor) || empty($room_number) || empty($bedNumber) || empty($location) || empty($phone) || empty($department_2)) 
                // {
                //     $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
                //     $result = json_encode($return);
                // } 
                // else 
                // {
                    //判断人员信息表中是否有此人员的信息，若已有则报错
                    // $query_people = $this->db->get_where('dorm_livepeople' ,array('idNumber' => $idNumber));
                    $query_people = $this->db->get_where('dorm_bed' ,array('idNumber' => $idNumber));
                    if($query_people->num_rows()>0)
                    {
                        $return = array('res' => '40002', 'msg' => '已入住，不允许重复入住' ,'data' => '');
                        $result = json_encode($return);
                    } 
                    else 
                    {
                        // if($company == '0')
                        // {
                            //取人员信息数据
                            // $query = $this->db->get_where('dorm_stay_retreat_tune' ,array('idNumber' => $idNumber));
                        
                            //调用方法更新记录表
                            $query_stay_retreat_tune = $this->Check_in->update_recording($idNumber, $jobNumber, $job, $area_number, $floor_number, $dorm_floor, $room_number, $bedNumber, $liveDate, $name, $department_2, $department_3, $sex, $phone, $location, $company);
        
                            $check_in_address = $area_number .'*' .$floor_number .'*' .$room_number .'*' .$bedNumber;
    
                            // $jobNumber = $query->row()->jobNumber;
                            // $sex = $query->row()->sex;
                            // $department = $query->row()->department;
                            // $job = $query->row()->job;
                            // $location = $query->row()->location;
                            // $phone = $query->row()->phone;
                            // $emergencyContact = $query->row()->emergencyContact;
                            // $relationShip = $query->row()->relationShip;
                            // $emergencyPhone = $query->row()->emergencyPhone;
    
                            //入住人员信息更新
                            // $query_livepeople = $this->Check_in->add_livepeople($area_number, $floor_number, $dorm_floor, $room_number, $check_in_address, $name, $idNumber, $sex, $departmen, $location, $phone, $liveDate, $bedNumber, $remarks, $company);
                            $query_livepeople = $this->Check_in->add_livepeople($area_number, $floor_number, $dorm_floor, $room_number, $check_in_address, $name, $idNumber, $jobNumber ,$sex, $department_2, $department_3, $job, $location, $phone, $liveDate, $bedNumber, $remarks, $company);
    
                            // //床位表更新
                            // $query_bed = $this->Check_in->add_bed($area_number, $floor_number, $dorm_floor, $room_number, $idNumber, $name, $sex, $department, $phone, $bedNumber, $remarks, $company);
                            $query_bed = $this->Check_in->add_bed($area_number, $floor_number, $dorm_floor, $room_number, $idNumber, $jobNumber, $name, $sex, $department_2, $department_3, $job, $phone, $bedNumber, $remarks, $company);

                            //水电表数据更新
                            // $query_manday = $this->Check_in->add_manday($area_number, $floor_number, $room_number, $name, $jobNumber, $liveDate);
                        // }
                        // elseif($company == '1')
                        // {
                        //     //取非公司人员记录表中的工号进行更新
                        //     $temporaryEmployee = $this->temporaryEmployee();
                        //     $temporaryEmployee = json_decode($temporaryEmployee);
                        //     if($temporaryEmployee->res = '40000')
                        //     {
                        //         $temporaryJobNumber = (substr($temporaryEmployee->data, 6, 1) + 1). substr($temporaryEmployee->data, 6);
                        //     }
                        //     else
                        //     {
                        //         $temporaryJobNumber = 'LS00001';
                        //     }
    
                        //     //调用方法更新记录表
                        //     $query_stay_retreat_tune = $this->Check_in->update_recording($idNumber, $area_number, $floor_number, $dorm_floor, $room_number, $bedNumber, $liveDate, $name, $department, $sex, $phone, $location, $company, $temporaryJobNumber);
        
                        //     $check_in_address = $area_number .'*' .$floor_number .'*' .$room_number .'*' .$bedNumber;
    
                        //     //入住人员信息更新
                        //     // $query_livepeople = $this->Check_in->add_livepeople($area_number, $floor_number, $dorm_floor, $room_number, $check_in_address, $name, $jobNumber, $idNumber, $sex, $department, $job, $location, $phone, $emergencyContact, $relationShip, $emergencyPhone, $liveDate, $bedNumber, $remarks);
                        //     $query_livepeople = $this->Check_in->add_livepeople($area_number, $floor_number, $dorm_floor, $room_number, $check_in_address, $name, $idNumber, $sex, $department, $location, $phone, $liveDate, $bedNumber, $remarks, $company, $temporaryJobNumber);
    
                        //     // //床位表更新
                        //     // $query_bed = $this->Check_in->add_bed($area_number, $floor_number, $dorm_floor, $room_number, $idNumber, $jobNumber, $name, $sex, $department, $phone, $bedNumber, $remarks);
                        //     $query_bed = $this->Check_in->add_bed($area_number, $floor_number, $dorm_floor, $room_number, $idNumber, $name, $sex, $department, $phone, $bedNumber, $remarks, $company, $temporaryJobNumber);
                        // }
                            
                        //取入住记录信息进行展示
                        // $where3 = array('area_number' => $area_number ,'floor_number' => $floor_number ,'room_number' => $room_number);
                        // $query_recording = $this->db->get_where('dorm_stay_retreat_tune' ,array('idNumber' => $idNumber));
                        $query_recording = $this->db->query("SELECT * FROM dorm_stay_retreat_tune WHERE idNumber = '".$idNumber."' ORDER BY liveDate DESC LIMIT 1");
    
                        //取这个房间的实际入住人数进行更新
                        $query_room = $this->db->get_where('dorm_roominfor', array('area_number' => $area_number ,'floor_number' => $floor_number ,'room_number' => $room_number));
    
                        //对象数组转数组
                        $peopleNumber = (array)$query_room->result()[0];
    
                        //将宿舍实际人数+1
                        $peopleNumber_add = $peopleNumber['peopleNumber'] + 1;
    
                        //将宿舍剩余可住人数-1
                        $remainpeople_add = $peopleNumber['remainNumber'] - 1;
    
                        $data_room = array(
                            'peopleNumber' => $peopleNumber_add,
                            'remainNumber' => $remainpeople_add
                        );
                        //将宿舍实际人数,宿舍剩余可住人数进行更新
                        $where_room = array('area_number' => $area_number ,'floor_number' => $floor_number ,'room_number' => $room_number);
                        $this->db->where($where_room);
                        $this->db->update('dorm_roominfor' ,$data_room);
                        $query_roominfor = $this->db->affected_rows();

                        if ($query_stay_retreat_tune  && $query_livepeople && $query_bed  && $query_roominfor) 
                        {
                            $return_su = array('res' => '40000', 'msg' => '入住成功', 'data' => $query_recording->result());
                            $result = json_encode($return_su);
                        } 
                        else 
                        {
                            $return_fa = array('res' => '40001', 'msg' => '入住失败', 'data' => '');
                            $result = json_encode($return_fa);
                        }
                    }
                // }
            }
            else
            {
                if ( $name == '' || $idNumber == '' || $liveDate == '' || $area_number == '' || $floor_number == '' || $dorm_floor == '' || $room_number == '' || $bedNumber == '' || $location == '' || $phone == '' || $company == '') 
                {
                    $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
                    $result = json_encode($return);
                } 
                else 
                {
                    //判断人员信息表中是否有此人员的信息，若已有则报错
                    $query_people = $this->db->get_where('dorm_livepeople' ,array('idNumber' => $idNumber));
                    if($query_people->num_rows()>0)
                    {
                        $return = array('res' => '40002', 'msg' => '已入住，不允许重复入住' ,'data' => '');
                        $result = json_encode($return);
                    } 
                    else 
                    {
                        // if($company == '0')
                        // {
                            //取人员信息数据
                            // $query = $this->db->get_where('dorm_stay_retreat_tune' ,array('idNumber' => $idNumber));
                        
                            //调用方法更新记录表
                            // $query_stay_retreat_tune = $this->Check_in->update_recording($idNumber, $area_number, $floor_number, $dorm_floor, $room_number, $bedNumber, $liveDate, $name, $department, $sex, $phone, $location, $company);
        
                            // $check_in_address = $area_number .'*' .$floor_number .'*' .$room_number .'*' .$bedNumber;
    
                            // // $jobNumber = $query->row()->jobNumber;
                            // // $sex = $query->row()->sex;
                            // // $department = $query->row()->department;
                            // // $job = $query->row()->job;
                            // // $location = $query->row()->location;
                            // // $phone = $query->row()->phone;
                            // // $emergencyContact = $query->row()->emergencyContact;
                            // // $relationShip = $query->row()->relationShip;
                            // // $emergencyPhone = $query->row()->emergencyPhone;
    
                            // //入住人员信息更新
                            // // $query_livepeople = $this->Check_in->add_livepeople($area_number, $floor_number, $dorm_floor, $room_number, $check_in_address, $name, $jobNumber, $idNumber, $sex, $department, $job, $location, $phone, $emergencyContact, $relationShip, $emergencyPhone, $liveDate, $bedNumber, $remarks);
                            // $query_livepeople = $this->Check_in->add_livepeople($area_number, $floor_number, $dorm_floor, $room_number, $check_in_address, $name, $idNumber, $sex, $department, $location, $phone, $liveDate, $bedNumber, $remarks, $company);
    
                            // // //床位表更新
                            // // $query_bed = $this->Check_in->add_bed($area_number, $floor_number, $dorm_floor, $room_number, $idNumber, $jobNumber, $name, $sex, $department, $phone, $bedNumber, $remarks);
                            // $query_bed = $this->Check_in->add_bed($area_number, $floor_number, $dorm_floor, $room_number, $idNumber, $name, $sex, $department, $phone, $bedNumber, $remarks, $company);
    
                            //水电表数据更新
                            // $query_manday = $this->Check_in->add_manday($area_number, $floor_number, $room_number, $name, $jobNumber, $liveDate);
                        // }
                        // elseif($company == '1')
                        // {
                            //取非公司人员记录表中的工号进行更新
                            $temporaryEmployee = $this->temporaryEmployee();
                            $temporaryEmployee = json_decode($temporaryEmployee);
                            if($temporaryEmployee->res = '40000')
                            {
                                $temporaryJobNumber = (substr($temporaryEmployee->data, 6, 1) + 1). substr($temporaryEmployee->data, 6);
                            }
                            else
                            {
                                $temporaryJobNumber = 'LS00001';

                                $dorm_temporaryemployee_record = array(
                                    'jobNumber' => $temporaryJobNumber,
                                    'idNumber' => $idNumber,
                                    'name' => $name
                                );

                                $this->db->insert('dorm_temporaryemployee_record', $dorm_temporaryemployee_record);
                            }
    
                            //调用方法更新记录表
                            $query_stay_retreat_tune = $this->Check_in->update_recording($temporaryJobNumber, $area_number, $floor_number, $dorm_floor, $room_number, $bedNumber, $liveDate, $name, $department_2, $department_3, $sex, $phone, $location, $company, $temporaryJobNumber);
        
                            $check_in_address = $area_number .'*' .$floor_number .'*' .$room_number .'*' .$bedNumber;
    
                            //入住人员信息更新
                            // $query_livepeople = $this->Check_in->add_livepeople($area_number, $floor_number, $dorm_floor, $room_number, $check_in_address, $name, $jobNumber, $idNumber, $sex, $department, $job, $location, $phone, $emergencyContact, $relationShip, $emergencyPhone, $liveDate, $bedNumber, $remarks);
                            $query_livepeople = $this->Check_in->add_livepeople($area_number, $floor_number, $dorm_floor, $room_number, $check_in_address, $name, $idNumber, $sex, $department_2, $department_3, $location, $phone, $liveDate, $bedNumber, $remarks, $company, $temporaryJobNumber);
    
                            // //床位表更新
                            // $query_bed = $this->Check_in->add_bed($area_number, $floor_number, $dorm_floor, $room_number, $idNumber, $jobNumber, $name, $sex, $department, $phone, $bedNumber, $remarks);
                            $query_bed = $this->Check_in->add_bed($area_number, $floor_number, $dorm_floor, $room_number, $idNumber, $name, $sex, $department_2, $department_3, $phone, $bedNumber, $remarks, $company, $temporaryJobNumber);
                        // }
                            
                        //取入住记录信息进行展示
                        // $where3 = array('area_number' => $area_number ,'floor_number' => $floor_number ,'room_number' => $room_number);
                        // $query_recording = $this->db->get_where('dorm_stay_retreat_tune' ,array('idNumber' => $idNumber));
                        $query_recording = $this->db->query("SELECT * FROM dorm_stay_retreat_tune WHERE idNumber = '".$idNumber."' OR jobNumber = '".$temporaryJobNumber."' ORDER BY liveDate DESC LIMIT 1");
    
                        //取这个房间的实际入住人数进行更新
                        $query_room = $this->db->get_where('dorm_roominfor', array('area_number' => $area_number ,'floor_number' => $floor_number ,'room_number' => $room_number));
    
                        //对象数组转数组
                        $peopleNumber = (array)$query_room->result()[0];
    
                        //将宿舍实际人数+1
                        $peopleNumber_add = $peopleNumber['peopleNumber'] + 1;
    
                        //将宿舍剩余可住人数-1
                        $remainpeople_add = $peopleNumber['remainNumber'] - 1;
    
                        $data_room = array(
                            'peopleNumber' => $peopleNumber_add,
                            'remainNumber' => $remainpeople_add
                        );
                        //将宿舍实际人数,宿舍剩余可住人数进行更新
                        $where_room = array('area_number' => $area_number ,'floor_number' => $floor_number ,'room_number' => $room_number);
                        $this->db->where($where_room);
                        $this->db->update('dorm_roominfor' ,$data_room);
                        $query_roominfor = $this->db->affected_rows();
                        if ($query_stay_retreat_tune  && $query_livepeople && $query_bed  && $query_roominfor) 
                        {
                            $return_su = array('res' => '40000', 'msg' => '入住成功', 'data' => $query_recording->result());
                            $result = json_encode($return_su);
                        } 
                        else 
                        {
                            $return_fa = array('res' => '40001', 'msg' => '入住失败', 'data' => '');
                            $result = json_encode($return_fa);
                        }
                    }
                }
            }
            return $result;
        }

        //  入住方法：申请人节点
        // public function check_in_applicant($RY_name, $RY_degsonid, $RY_sex, $RY_idcardnum, $RY_location, $RY_phone, $RY_address, $RY_emergency_contact, $RY_relationship, $RY_emergency_phone, $RY_reason)
        // {
        //     //必输字段未输则报错
        //     if ($RY_name == '' || $RY_degsonid == '' || $RY_sex == '' || $RY_idcardnum == '' || $RY_location == '' || $RY_phone == '' || $RY_address == '' || $RY_emergency_contact == '' || $RY_relationship == '' || $RY_emergency_phone == '' || $RY_reason == '') {
        //         $return = array('res' => '40002', 'msg' => '请输入必填字段');
        //         $result = json_encode($return);
        //     } else {
        //         $query = $this->db->get_where('dorm_stay_retreat_tune', array('SQ_RY_number' => $RY_degsonid));
        //         if ($query->num_rows() > 0) {
        //             $return = array('res' => '40002', 'msg' => '不允许重复入住');
        //             $result = json_encode($return);
        //         } else {
        //             //住宿/调宿/退宿表数据
        //             $type = 1; //已申请
        //             $data = array(
        //                 'SQ_RY_name' => $RY_name,
        //                 'SQ_RY_number' => $RY_degsonid,
        //                 'SQ_RY_sex' => $RY_sex,
        //                 'SQ_RY_idcardnum' => $RY_idcardnum,
        //                 'SQ_RY_location' => $RY_location,
        //                 'SQ_RY_phone' => $RY_phone,
        //                 'SQ_RY_address' => $RY_address,
        //                 'SQ_liaison' => $RY_emergency_contact,
        //                 'SQ_relationship' => $RY_relationship,
        //                 'SQ_liaison_phone' => $RY_emergency_phone,
        //                 'SQ_reason' => $RY_reason,
        //                 'SQ_type' => $type
        //             );
        //             //数据插入表
        //             $this->db->insert('dorm_stay_retreat_tune', $data);
        //             $return = $this->db->affected_rows();
        //             $query1 = $this->db->get_where('dorm_stay_retreat_tune', array('SQ_RY_number' => $RY_degsonid));
        //             // $query = $this->db->get_where('dorm_stay_retreat_tune' ,array('SQ_RY_idcardnum' => $RY_idcardnum ,'SQ_type' => $type));
        //             // $workflowname = '住宿';
        //             // $isremark = 0;
        //             // $date_now = date("Y-m-d");
        //             //流程表数据
        //             // $data1 = array(
        //             //     'requestid' => $query->row(0)->ID,
        //             //     'userid' => '',
        //             //     'workflowid' => $type,
        //             //     'workflowname' => $workflowname,
        //             //     'isremark' => $isremark,
        //             //     'careatedate' => $query->row(0)->SQ_date,
        //             //     'receivedate' => $date_now,
        //             //     'operatedate' => ''
        //             // );
        //             //数据插入表
        //             // $this->db->insert('dorm_process' ,$data1);
        //             if ($return) {
        //                 //申请成功
        //                 $return_su = array('res' => '40000', 'msg' => $RY_name . '申请成功', 'data' => $query1->row(0));
        //                 $result = json_encode($return_su);
        //             } else {
        //                 //申请失败
        //                 $return_fa = array('res' => '40001', 'msg' => $RY_name . '申请失败', 'data' => '');
        //                 $result = json_encode($return_fa);
        //             }
        //         }
        //     }
        //     return $result;
        // }

        // //入住方法：人资节点
        // public function check_in_hr($requestid ,$RY_department ,$RY_job ,$username)
        // {
        //     //必输字段未输则报错
        //     if($requestid == '')
        //     {
        //         $return = array('res' => '40002', 'msg' => '请输入必填字段');
        //         $result = json_encode($return);
        //     }
        //    else
        //     {
        //         //根据resquestid与id相等取值
        //         $query = $this->db->get_where('dorm_stay_retreat_tune' ,array('ID' ,$requestid));
        //         if($query->num_rows()>0)
        //         {
        //             //住宿/调宿/退宿表数据
        //             $data = array(
        //                 'SQ_RY_department' => $RY_department,
        //                 'SQ_RY_job' => $RY_job,
        //             );
        //             //更新表
        //             $this->db->where('ID' ,$requestid);
        //             $this->db->update('dorm_stay_retreat_tune' ,$data);
        //             $return1 = $this->db->affected_rows();
        //             if($return1)
        //             {
        //                 //当前日期
        //                 $date_now = date("Y-m-d");
        //                 //1:已操作 0：未操作
        //                 $isremark = 1;
        //                 $data1 = array(
        //                     'userid' => $username,
        //                     'isremark' => $isremark,
        //                     'operatedate' => $date_now,
        //                 );
        //                 //更新表
        //                 $this->db->where('requestid' ,$requestid);
        //                 $this->db->update('dorm_process' ,$data1);
        //                 //审批成功
        //                 $return_su = array('res' => '40000' ,'msg' => '审批成功' ,'data' => $requestid);
        //                 $result = json_encode($return_su);
        //             }
        //            else
        //             {   
        //                 //审批失败
        //                 $return_fa = array('res' => '40001' ,'msg' => '审批失败' ,'data' => $requestid);
        //                 $result = json_encode($return_fa);
        //             }
        //         }
        //        else
        //        {
        //            //没有符合条件的数据
        //            $return_fa1 = array('res' => '40001' ,'msg' => '没有查到符合条件的数据');
        //            $result = json_encode($return_fa1);
        //        }
        //     }
        //     return $result;
        // }

        // // 入住方法:宿管员节点
        // public function check_in_admin($RY_degsonid, $RY_sex, $RY_idcardnum, $RY_location, $RY_phone, $RY_address, $RY_emergency_contact, $RY_relationship, $RY_emergency_phone, $RY_reason ,$RY_name, $AR_number, $SSL_number, $SS_floor, $SS_number, $RY_bed ,$RY_remarks ,$Live_date)
        // {
        //     // if ($RY_name == '' || $AR_number == '' || $SSL_number == '' || $SS_floor == '' || $SS_number == '' || $RY_bed == ''|| $RY_degsonid == '' || $RY_sex == '' || $RY_idcardnum == '' || $RY_location == '' || $RY_phone == '' || $RY_address == '' || $RY_emergency_contact == '' || $RY_relationship == '' || $RY_emergency_phone == '' || $RY_reason == '' ) {  
        //     if ( $RY_name == '' || $Live_date == '' || $RY_sex == '' || $RY_idcardnum == '' || $RY_phone == '') {
        //         //必输字段未输则报错
        //         $return = array('res' => '40002', 'msg' => '请输入必填字段');
        //         $result = json_encode($return);
        //     } else {
        //         $RY_live_check = 1;
        //         $where1 = array('RY_idcardnum' => $RY_idcardnum ,'RY_live_check' => $RY_live_check);   
        //         $this->db->select('*');
        //         $this->db->where($where1);
        //         $query2 = $this->db->get('dorm_livepeople');
        //         if($query2->num_rows()>0)
        //         {
        //             $return = array('res' => '40002', 'msg' => '已入住，不允许重复入住');
        //             $result = json_encode($return);
        //         } else {
        //         $SQ_type = 1;
        //         $data = array(
        //             // 'SQ_RY_name' => $RY_name,
        //             // 'AR_number' => $AR_number,
        //             // 'SSL_number' => $SSL_number,
        //             // 'SS_floor' => $SS_floor,
        //             // 'SQ_SS_number' => $SS_number,
        //             // 'SQ_bed' => $RY_bed,
        //             // //    'SQ_wardrobe' => $RY_wardrobe,
        //             // 'SQ_RY_number' => $RY_degsonid,
        //             // 'SQ_RY_sex' => $RY_sex,
        //             // 'SQ_RY_idcardnum' => $RY_idcardnum,
        //             // 'SQ_RY_location' => $RY_location,
        //             // 'SQ_RY_phone' => $RY_phone,
        //             // 'SQ_RY_address' => $RY_address,
        //             // 'SQ_liaison' => $RY_emergency_contact,
        //             // 'SQ_relationship' => $RY_relationship,
        //             // 'SQ_liaison_phone' => $RY_emergency_phone,
        //             // 'SQ_reason' => $RY_reason,
        //             // 'SQ_type' => $type
        //             'SQ_live_date' => $Live_date,
        //             'AR_number' => $AR_number,
        //             'SSL_number' => $SSL_number,
        //             'SS_floor' => $SS_floor,
        //             'SQ_SS_number' => $SS_number,
        //             'SQ_RY_idcardnum' => $RY_idcardnum,
        //             'SQ_RY_number' => $RY_degsonid,
        //             'SQ_RY_name' => $RY_name,
        //             'SQ_RY_sex' => $RY_sex,
        //             'SQ_RY_phone' => $RY_phone,
        //             'SQ_RY_address' => $RY_address,
        //             'SQ_bed' => $RY_bed,
        //             'SQ_RY_location' => $RY_location,
        //             'SQ_liaison' => $RY_emergency_contact,
        //             'SQ_relationship' => $RY_relationship,
        //             'SQ_liaison_phone' => $RY_emergency_phone,
        //             'SQ_reason' => $RY_reason,
        //             'SQ_remarks' => $RY_remarks,
        //             'SQ_type' => $SQ_type
        //         );

        //         //人员入住信息数据
        //         $RY_live_check = 1;
        //         $data1 = array(
        //             'AR_number' => $AR_number,
        //             'SSL_number' => $SSL_number,
        //             'RY_number' => $SS_number,
        //             'RY_name' => $RY_name,
        //             'RY_idcardnum' => $RY_idcardnum,
        //             'RY_degsonid' => $RY_degsonid,
        //             'RY_sex' => $RY_sex,
        //             'SS_floor' => $SS_floor,
        //             'RY_degsonid' => $RY_degsonid,
        //             // 'RY_department' => $RY_department,
        //             // 'RY_job' => $RY_job,
        //             'RY_phone' => $RY_phone,
        //             'RY_live_check' => $RY_live_check,
        //             'RY_live_date' => $Live_date,
        //             'RY_bed' => $RY_bed,
        //             // 'RY_wardrobe' => $RY_wardrobe,
        //             'RY_remarks' => $RY_remarks,  
        //         );

        //         //信息写入床位
        //         $RY_whether = 1;
        //         $data2 = array(
        //             'AR_number' => $AR_number,
        //             'SSL_number' => $SSL_number,
        //             'SS_floor' => $SS_floor,
        //             'SS_number' => $SS_number,
        //             'RY_idcardnum' => $RY_idcardnum,
        //             'RY_name' => $RY_name,
        //             'RY_sex' => $RY_sex,
        //             'RY_degsonid' => $RY_degsonid,
        //             'RY_phone' => $RY_phone,
        //             'RY_whether' => $RY_whether,
        //             'RY_remarks' => $RY_remarks
        //         );

        //         $where2 = array('AR_number' => $AR_number ,'SSL_number' => $SSL_number ,'SS_number' => $SS_number ,'RY_bed' => $RY_bed);
        //         $this->db->insert('dorm_stay_retreat_tune', $data);
        //         $query = $this->db->affected_rows();
        //         $this->db->insert('dorm_livepeople' ,$data1);
        //         $query2 = $this->db->affected_rows();
        //         $this->db->where($where2);
        //         $this->db->update('dorm_bed' ,$data2);
        //         $query3 = $this->db->affected_rows();
        //         $where = array('SQ_RY_idcardnum' => $RY_idcardnum);
        //         $this->db->select('*');
        //         $this->db->where($where);
        //         $query1 = $this->db->get('dorm_stay_retreat_tune');
        //         $where3 = array('AR_number' => $AR_number ,'SSL_number' => $SSL_number ,'SS_number' => $SS_number);
        //         //取这个房间的实际入住人数进行更新
        //         $this->db->select('SS_peoplenumber');
        //         $this->db->where($where3);
        //         $query4 = $this->db->get('dorm_roominfor');
        //         $SS_peoplenumber = (array)$query4->result()[0];
        //         $SS_peoplenumber_add = $SS_peoplenumber['SS_peoplenumber'] + 1;
        //         $data3 = array(
        //             'SS_peoplenumber' => $SS_peoplenumber_add
        //         );
        //         $this->db->where($where3);
        //         $this->db->update('dorm_roominfor' ,$data3);
        //         $query5 = $this->db->affected_rows();
        //         if ($query && $query2 && $query3 && $query5) {
        //             $return_su = array('res' => '40000', 'msg' => '入住成功', 'data' => $query1->row());
        //             $result = json_encode($return_su);
        //         } else {
        //             $return_fa = array('res' => '40001', 'msg' => '入住失败', 'data' => '');
        //             $result = json_encode($return_fa);
        //         }
        //     }
            
        //     }
        //     return $result;
        // }

        // //人员入住方法
        // public function check_in_admin($RY_name ,$RY_live_date ,$RY_idcardnum ,$RY_sex ,$RY_degsonid ,$RY_department ,$RY_job ,$RY_phone ,$RY_remarks ,$SS_temporary ,$AR_number ,$SSL_number ,$SS_floor ,$RY_number ,$RY_bed ,$RY_wardrobe ,$SQ_use_number = array('SQ_use_number'))
        // {
        //     if($RY_name == '' || $RY_live_date == '' || $RY_idcardnum == '' || $RY_sex == '' || $RY_degsonid == '' || $RY_department == '' || $RY_job == '' || $RY_phone == '' || $RY_remarks == '' || $SS_temporary == '' || $AR_number == '' || $SSL_number == '' || $SS_floor == '' || $RY_number == '' || $RY_bed == '' || $RY_wardrobe == '' || $SQ_use_number == '')
        //     {
        //         //必输字段未输则报错
        //         $return = array('res' => '40002', 'msg' => '请输入必填字段');
        //         $result = json_encode($return);
        //     }
        //    else
        //     {

        //     //    $query = $this->db->get_where('dorm_process' ,array('requestid' => $requestid));
        //           $query1 = $this->db->get_where('dorm_sslmanage' ,array('AR_name' => $AR_number ,'SSL_name' => $SSL_number));
        //     //    $query2 = $this->db->get_where('dorm_stay_retreat_tune' ,array('ID' ,$requestid));
        //     //    $query3 = $this->db->get_where('dorm_livepeople' ,array('RY_idcardnum' => $query2->row(0)->SQ_RY_idcardnum));
        //     //    $query4 = $this->db->get_where('dorm_livepeople' ,array('RY_number' =>$query3->row(0)->RY_number));
        //     //    if($query4->num_rows()>0)
        //     //    {
        //     //        foreach($query4->result() as $row);
        //     //    }               
        //        if($query->num_rows()>0)
        //        {
        //            //住宿/调宿/退宿表数据
        //            $data = array(
        //                'AR_number' => $AR_number,
        //                'SSL_number' => $SSL_number,
        //                'SS_floor' => $SS_floor,
        //                'SQ_SS_number' => $RY_number,
        //                'SQ_bed' => $RY_bed,
        //                'SQ_wardrobe' => $RY_wardrobe
        //            );
        //            //人员入住信息数据
        //            $RY_live_check = 1;
        //            $data1 = array(
        //                'AR_number' => $AR_number,
        //                'SSL_number' => $SSL_number,
        //                'RY_number' => $RY_number,
        //                'RY_name' => $RY_name,
        //                'RY_idcardnum' => $RY_idcardnum,
        //                'RY_degsonid' => $RY_degsonid,
        //                'RY_sex' => $RY_sex,
        //                'RY_department' => $RY_department,
        //                'RY_job' => $RY_job,
        //             //    'RY_location' => $query2->row(0)->SQ_RY_location,
        //             //    'RY_address' => $query2->row(0)->SQ_RY_address,
        //                'RY_phone' => $RY_phone,
        //             //    'RY_emergency_contact' => $query2->row(0)->SQ_liaison,
        //             //    'RY_relationship' => $query2->row(0)->SQ_relationship,
        //             //    'RY_emergency_phone' => $query2->row(0)->SQ_liaison_phone,
        //             //    'RY_reason' => $query2->row(0)->SQ_reason,
        //                'RY_live_check' => $RY_live_check,
        //                'RY_live_date' => $RY_live_date,
        //                'RY_bed' => $RY_bed,
        //                'RY_wardrobe' => $RY_wardrobe,
        //                'RY_remarks' => $RY_remarks,  
        //            );
        //            //当前日期
        //            $date_now = date("Y-m-d");
        //            //领用物品更新
        //            $data2 = array(
        //                'RY_idcardnum' => $RY_idcardnum,
        //                'SQ_RY_number' => $RY_number,
        //                'SQ_RY_name' => $RY_name,
        //                'SQ_RY_sex' => $RY_sex,
        //                'SQ_RY_department' => $RY_department,
        //                'SQ_RY_job' => $RY_job,
        //                'SQ_SS_number' => $SS_number,
        //                'SQ_usedate' => $date_now,
        //                'SQ_roommate' => $row->SQ_RY_number ,$row->SQ_RY_name,
        //            );
        //            //更新表
        //            $this->db->where('ID' ,$requestid);
        //            $this->db->update('dorm_stay_retreat_tune' ,$data);
        //            $return = $this->db->affected_rows();
        //            //更新表
        //            $this->db->where('RY_idcardnum' ,$query2->row(0)->SQ_RY_idcardnum);
        //            $this->db->update('dorm_livepeople' ,$data1);
        //            //数据插入表
        //            $this->db->insert('dorm_article' ,$data2);
        //            if($return)
        //            {
        //                //入住成功
        //                $return_su = array('res' => '40000' ,'msg' => '入住成功' ,'');
        //                $result = json_encode($return_su);
        //            }
        //           else
        //            {
        //                //入住失败
        //                $return_fa = array('res' => '40001' ,'msg' => '入住失败');
        //                $result = json_encode($return_fa);
        //            }
        //        }
        //       else
        //        {
        //         //没有查到符合条件的数据
        //         $return_fa1 = array('res' => '40001' ,'msg' => '没有查到符合条件的数据');
        //         $result = json_encode($return_fa1);
        //       }
        //     }
        //     return $result;
        // }


        /**
         * @description: 入住筛选界面方法:取宿舍楼
         * @param {area_number}
         * @return {*}
         */        
        public function check_condition($area_number)
        {
            //必输字段未输则报错
            if ($area_number == '') 
            {
                $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
                $result = json_encode($return);
            } 
            else 
            {
                $query = $this->db->get_where('dorm_sslmanage', array('area_number' => $area_number));
                if ($query->num_rows() > 0) 
                {
                    //查询成功
                    $return_su = array('res' => '40000', 'msg' => '查询成功', 'floor_number' => $query->row()->floor_number, 'floor_name' => $query->row()->floor_name);
                    $result = json_encode($return_su);
                } 
                else 
                {
                    //查询失败
                    $return_fa = array('res' => '40001', 'msg' => '查询无数据' ,'data' => '');
                    $result = json_encode($return_fa);
                }
            }
            return $result;
        }

        /**
         * @description: 入住筛选界面方法:取楼层
         * @param {area_number, floor_number}
         * @return {*}
         */        
        public function check_condition_floor($area_number, $floor_number)
        {
            //必输字段未输则报错
            if ($area_number == '' || $floor_number == '') 
            {
                $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
                $result = json_encode($return);
            } 
            else 
            {
                // $where = array('area_number' => $area_number, 'floor_number' => $floor_number);
                // $this->db->select('floorNumber');
                // $this->db->where($where);
                // $query = $this->db->get('dorm_sslmanage');
                $arr = [];
                if($area_number = '1585' && $floor_number = '1')
                {
                    $arr = [3,4,5,6];
                }
                elseif($area_number = '1585' && $floor_number = '2')
                {
                    $arr = [1];
                }
                elseif($area_number = '333' && $floor_number = '3')
                {
                    $arr = [1,2,3];
                }
                elseif($area_number = '178' && $floor_number = '4')
                {
                    $arr = [1];
                }
                if (count($arr) > 0)
                 {
                    $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $arr);
                    $result = json_encode($return_su);
                } 
                else 
                {
                    $return_fa = array('res' => '40001', 'msg' => '查询无数据' ,'data' => '');
                    $result = json_encode($return_fa);
                }
                return $result;
            }
        }

        
        // /**
        //  * @description: 入住筛选界面方法:取宿舍
        //  * @param {area_number,floor_number,dorm_floor,department,sex}
        //  * @return {*}
        //  */        
        // public function check_condition_number($area_number, $floor_number, $dorm_floor, $department, $company, $sex)
        // {
        //     $j = -1;
        //     $X = -1;
        //     $arr = [];
        //     $arr1 = [];
        //     if($company == '0')
        //     {
        //         if ($area_number == '' || $floor_number == '' || $dorm_floor == '' || $department == '' || $sex == '' || $company == '') 
        //         {
        //             $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
        //             $result = json_encode($return);
        //         } 
        //         else
        //         {
        //                 $data_dorm_roominfor = $this->db->query("SELECT room_number FROM dorm_roominfor WHERE area_number LIKE '%".$area_number."%' AND floor_number LIKE '%".$floor_number."%' AND dorm_floor LIKE '%".$dorm_floor."%' AND room_sex LIKE '%".$sex."%' AND remainNumber > 0 ORDER BY remainNumber");
        //                 $query_dorm_roominfor = $data_dorm_roominfor->result();
        //                 for($i=0 ;$i<$data_dorm_roominfor->num_rows() ;$i++)
        //                 {
        //                     $query_dorm_roominfor1 = $data_dorm_roominfor->result()[$i]->room_number;
        //                     $data_livepeople = $this->db->query("SELECT DISTINCT room_number FROM dorm_livepeople WHERE area_number LIKE '%".$area_number."%' AND floor_number LIKE '%".$floor_number."%' AND department3 LIKE '%".$department."%' AND room_number = '".$query_dorm_roominfor1."'");
        //                     if($data_livepeople->num_rows() > 0)
        //                     {
        //                         $j = $j+1;
        //                         $query_livepeople = $data_livepeople->result();
        //                         $query_livepeople = (array)$query_livepeople[0];
        //                         array_push($arr, $query_livepeople['room_number']);
        //                     }
        //                     else
        //                     {
        //                         $data_livepeople = $this->db->query("SELECT DISTINCT room_number FROM dorm_livepeople WHERE area_number LIKE '%".$area_number."%' AND floor_number LIKE '%".$floor_number."%' AND department2 LIKE '%".$department."%' AND room_number = '".$query_dorm_roominfor1."'");
        //                         if($data_livepeople->num_rows() > 0)
        //                         {
        //                             $j = $j+1;
        //                             $query_livepeople = $data_livepeople->result();
        //                             $query_livepeople = (array)$query_livepeople[0];
        //                             array_push($arr, $query_livepeople['room_number']);
        //                         }
        //                     }
        //                 }

        //                 $arr_people = [];
        //                 for($i=0 ;$i<count($arr) ;$i++)
        //                 {
        //                     $X = $X+1;

        //                     $room_number = $arr[$i];
        //                     $data_people = $this->db->query("SELECT room_number ,remainNumber FROM dorm_roominfor WHERE room_number = '".$room_number."'");
        //                     $query_people = $data_people->result();
        //                     $query_people= (array)$query_people[0];
        //                     $arr_people[$X] = array(
        //                         'room_number' => $query_people['room_number'],
        //                         'remainNumber' => $query_people['remainNumber']
        //                     );
        //                 }
        //                 if (count($arr_people) > 0) 
        //                 {
        //                     $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $arr_people);
        //                     $result = json_encode($return_su);
        //                 } 
        //                 else 
        //                 {
        //                     $return_fa = array('res' => '40001', 'msg' => '查询失败' ,'data' => '');
        //                     $result = json_encode($return_fa);
        //                 }
        //         }

        //     }
        //     else
        //     {
        //         if ($area_number == '' || $floor_number == '' || $dorm_floor == '' || $sex == '' || $company == '') 
        //         {
        //             $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
        //             $result = json_encode($return);
        //         } 
        //         else
        //         {
        //                 $data_dorm_roominfor = $this->db->query("SELECT room_number FROM dorm_roominfor WHERE area_number LIKE '%".$area_number."%' AND floor_number LIKE '%".$floor_number."%' AND dorm_floor LIKE '%".$dorm_floor."%' AND peopleNumber = 0");
        //                 if($data_dorm_roominfor)
        //                 {
        //                     $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $data_dorm_roominfor->result());
        //                     $result = json_encode($return_su);
        //                 }
        //                 else
        //                 {
        //                     $return_fa = array('res' => '40001', 'msg' => '' ,'data' => '');
        //                     $result = json_encode($return_fa);
        //                 }
        //         }
        //     }
        //     return $result;
        // }

        // /**
        //  * @description: 入住筛选界面方法:取宿舍
        //  * @param {area_number, floor_number, dorm_floor, department_2, department_3, company, sex, room_type}
        //  * @return {*}
        //  */        
        // public function check_condition_number($area_number, $floor_number, $dorm_floor, $department_2, $department_3, $company, $sex, $room_type, $live_empty)
        // {
        //     $j = -1;
        //     $X = -1;
        //     $arr = [];
        //     $arr[] = new stdClass;
        //     $arr1 = [];
        //     $sj1 = $area_number == '' ? ' 1 = 1 ' : " A.area_number LIKE '%".$area_number."%'";
        //     $sj2 = $floor_number == '' ? ' AND 1 = 1 ' : " AND A.floor_number LIKE '%".$floor_number."%'";
        //     $sj3 = $dorm_floor == '' ? ' AND 1 = 1 ' : " AND A.dorm_floor LIKE '%".$dorm_floor."%'";
        //     $sj4 = $department_2 == '' ? ' AND 1 = 1 ' : " AND department2 LIKE '%".$department_2."%'";
        //     $sj5 = $department_3 == '' ? ' AND 1 = 1 ' : " AND department3 LIKE '%".$department_3."%'";
        //     $sj6 = $sex == '' ? ' AND 1 = 1 ' : " AND room_sex LIKE '%".$sex."%'";
        //     $sj11 = $room_type == '' ? ' AND 1 = 1 ' : " AND room_type LIKE '%".$room_type."%'";
        //     if($company == '0')
        //     {
        //         if ($department_2 == '' || $sex == '' || $company == '') 
        //         {
        //             $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
        //             $result = json_encode($return);
        //         } 
        //         else
        //         {   
        //                 $sj10 = "AND remainNumber > 0 ORDER BY remainNumber";
        //                 $sql = "SELECT room_number FROM dorm_roominfor AS A WHERE".$sj1 .$sj2 .$sj3 .$sj6 .$sj11 .$sj10;
        //                 $data_dorm_roominfor = $this->db->query($sql, $sj1, $sj2, $sj3, $sj6, $sj11, $sj10);

        //                 // $data_dorm_roominfor = $this->db->query("SELECT room_number FROM dorm_roominfor WHERE area_number LIKE '%".$area_number."%' AND floor_number LIKE '%".$floor_number."%' AND dorm_floor LIKE '%".$dorm_floor."%' AND room_sex LIKE '%".$sex."%' AND remainNumber > 0 ORDER BY remainNumber");
        //                 $query_dorm_roominfor = $data_dorm_roominfor->result();
        //                 for($i=0 ;$i<$data_dorm_roominfor->num_rows() ;$i++)
        //                 {
        //                     $query_dorm_roominfor1 = $query_dorm_roominfor[$i]->room_number;
        //                     $sj7 = $query_dorm_roominfor1 == '' ? ' AND 1 = 1 ' : " AND A.room_number = '".$query_dorm_roominfor1."'";
        //                     $sql1 = "SELECT DISTINCT A.area_number, B.area_name, A.floor_number, B.floor_name, A.dorm_floor, A.room_number FROM dorm_livepeople AS A LEFT JOIN dorm_roominfor AS B
        //                              ON A.area_number = B.area_number AND A.floor_number = B.floor_number WHERE".$sj1 .$sj2 .$sj4 .$sj5 .$sj7;
        //                     // $data_livepeople = $this->db->query("SELECT DISTINCT room_number FROM dorm_livepeople WHERE area_number LIKE '%".$area_number."%' AND floor_number LIKE '%".$floor_number."%' AND department3 LIKE '%".$department_3."%' AND room_number = '".$query_dorm_roominfor1."'");
        //                     $data_livepeople = $this->db->query($sql1, $sj1, $sj2, $sj4, $sj5, $sj7);
        //                     if($data_livepeople->num_rows() > 0)
        //                     {
        //                         $arr[] = new stdClass();
        //                         $j = $j+1;
        //                         $query_livepeople = $data_livepeople->result();
        //                         $arr[$j]->area_number = $query_livepeople[0]->area_number;
        //                         $arr[$j]->area_name = $query_livepeople[0]->area_name;
        //                         $arr[$j]->floor_number = $query_livepeople[0]->floor_number;
        //                         $arr[$j]->floor_name = $query_livepeople[0]->floor_name;
        //                         $arr[$j]->dorm_floor = $query_livepeople[0]->dorm_floor;
        //                         $arr[$j]->room_number = $query_livepeople[0]->room_number;
        //                     }
        //                 }
        //                 $arr_people = [];
        //                 array_pop($arr);
        //                 if(count($arr) == 0)
        //                 {
        //                     for($i=0 ;$i<$data_dorm_roominfor->num_rows() ;$i++)
        //                     {
        //                         $query_dorm_roominfor1 = $query_dorm_roominfor[$i]->room_number;
        //                         $sj7 = $query_dorm_roominfor1 == '' ? ' AND 1 = 1 ' : " AND A.room_number = '".$query_dorm_roominfor1."'";
        //                         $sql1 = "SELECT DISTINCT A.area_number, B.area_name, A.floor_number, B.floor_name, A.dorm_floor, A.room_number FROM dorm_livepeople AS A LEFT JOIN dorm_roominfor AS B
        //                                  ON A.area_number = B.area_number AND A.floor_number = B.floor_number WHERE".$sj1 .$sj2 .$sj7 .$j11;
        //                         // $data_livepeople = $this->db->query("SELECT DISTINCT room_number FROM dorm_livepeople WHERE area_number LIKE '%".$area_number."%' AND floor_number LIKE '%".$floor_number."%' AND department3 LIKE '%".$department_3."%' AND room_number = '".$query_dorm_roominfor1."'");
        //                         $data_livepeople = $this->db->query($sql1, $sj1, $sj2, $sj7, $sj11);
        //                         if($data_livepeople->num_rows() > 0)
        //                         {
        //                             $arr[] = new stdClass();
        //                             $j = $j+1;
        //                             $query_livepeople = $data_livepeople->result();
        //                             $arr[$j]->area_number = $query_livepeople[0]->area_number;
        //                             $arr[$j]->area_name = $query_livepeople[0]->area_name;
        //                             $arr[$j]->floor_number = $query_livepeople[0]->floor_number;
        //                             $arr[$j]->floor_name = $query_livepeople[0]->floor_name;
        //                             $arr[$j]->dorm_floor = $query_livepeople[0]->dorm_floor;
        //                             $arr[$j]->room_number = $query_livepeople[0]->room_number;
        //                         }
        //                     }
        //                 }
        //                 for($i=0 ;$i<count($arr) ;$i++)
        //                 {
        //                     $X = $X+1;
        //                     $room_number = $arr[$i]->room_number;
        //                     $data_people = $this->db->query("SELECT room_number ,remainNumber FROM dorm_roominfor WHERE room_number = '".$room_number."'");
        //                     $query_people = $data_people->result();
        //                     $query_people= (array)$query_people[0];
        //                     $arr_people[$X] = array(
        //                         'area_number' => $arr[$i]->area_number,
        //                         'area_name' => $arr[$i]->area_name,
        //                         'floor_number' => $arr[$i]->floor_number,
        //                         'floor_name' => $arr[$i]->floor_name,
        //                         'dorm_floor' => $arr[$i]->dorm_floor,
        //                         'room_number' => $query_people['room_number'],
        //                         'remainNumber' => $query_people['remainNumber']
        //                     );
        //                 }
        //                 if (count($arr_people) > 0) 
        //                 {
        //                     $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $arr_people);
        //                     $result = json_encode($return_su);
        //                 } 
        //                 else 
        //                 {
        //                     $return_fa = array('res' => '40001', 'msg' => '查询失败' ,'data' => '');
        //                     $result = json_encode($return_fa);
        //                 }
        //         }

        //     }
        //     else
        //     {
        //         if ($area_number == '' || $floor_number == '' || $dorm_floor == '' || $sex == '' || $company == '') 
        //         {
        //             $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
        //             $result = json_encode($return);
        //         } 
        //         else
        //         {
        //                 $sj8 = "AND peopleNumber = 0";
        //                 $sql3 = "SELECT room_number FROM dorm_roominfor WHERE".$sj1 .$sj2 .$sj3;
        //                 // $data_dorm_roominfor = $this->db->query("SELECT room_number FROM dorm_roominfor WHERE area_number LIKE '%".$area_number."%' AND floor_number LIKE '%".$floor_number."%' AND dorm_floor LIKE '%".$dorm_floor."%' AND peopleNumber = 0");
        //                 $data_dorm_roominfor = $this->db->query($sql3, $sj1, $sj2, $sj3);
        //                 if($data_dorm_roominfor)
        //                 {
        //                     $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $data_dorm_roominfor->result());
        //                     $result = json_encode($return_su);
        //                 }
        //                 else
        //                 {
        //                     $return_fa = array('res' => '40001', 'msg' => '查询失败' ,'data' => '');
        //                     $result = json_encode($return_fa);
        //                 }
        //         }
        //     }
        //     return $result;
        // }

        /**
         * @description: 入住筛选界面方法:取宿舍
         * @param {area_number, floor_number, dorm_floor, department_2, department_3, company, sex, room_type}
         * @return {*}
         */        
        public function check_condition_number($area_number, $floor_number, $dorm_floor, $department_2, $department_3, $sex, $room_type, $live_empty, $limit)
        {
            if($limit != '')
            {
                $limit1 = ("$limit" - 1) * 10;
            }
            
            $arr = [];
            $sj1 = $area_number == '' ? ' 1 = 1 ' : " A.area_number LIKE '%".$area_number."%' ";
            $sj2 = $floor_number == '' ? ' AND 1 = 1 ' : " AND A.floor_number LIKE '%".$floor_number."%' ";
            $sj3 = $dorm_floor == '' ? ' AND 1 = 1 ' : " AND A.dorm_floor LIKE '%".$dorm_floor."%' ";
            $sj4 = $department_2 == '' ? ' AND 1 = 1 ' : " AND B.department2 LIKE '%".$department_2."%' ";
            $sj5 = $department_3 == '' ? ' AND 1 = 1 ' : " AND B.department3 LIKE '%".$department_3."%' ";
            $sj6 = $sex == '' ? ' AND 1 = 1 ' : " AND A.room_sex = '".$sex."' ";
            $sj7 = $room_type == '' ? ' AND 1 = 1 ' : " AND A.room_type = '".$room_type."' ";
            $sj10 = $limit == '' ? ' AND 1 = 1 ' : " Limit " . $limit1 . ",10 ";
            // $sj11 = " AND B.liveCheck = '' ";
            $sj11 = " AND B.check_inWhether = '' ";
            
            //入住空房间
            if($live_empty == '0')
            {   
                $sj8 = "AND A.peopleNumber = '0'";
                $sql = "SELECT DISTINCT A.area_number, A.area_name, A.floor_number, A.floor_name, A.dorm_floor, A.room_number, A.remainNumber FROM dorm_roominfor AS A LEFT JOIN dorm_bed AS B ON A.area_number = B.area_number 
                        AND A.floor_number = B.floor_number AND A.dorm_floor = B.dorm_floor AND A.room_number = B.room_number WHERE".$sj1 .$sj2 .$sj3 .$sj6 .$sj7 .$sj8 .$sj4 .$sj5 .$sj11 .$sj10;
                $data_dorm_roominfor = $this->db->query($sql, $sj1, $sj2, $sj3, $sj6, $sj7, $sj8, $sj4, $sj5, $sj11, $sj10);

                $sql_total = "SELECT DISTINCT A.area_number, A.area_name, A.floor_number, A.floor_name, A.dorm_floor, A.room_number, A.remainNumber FROM dorm_roominfor AS A LEFT JOIN dorm_bed AS B ON A.area_number = B.area_number 
                              AND A.floor_number = B.floor_number AND A.dorm_floor = B.dorm_floor AND A.room_number = B.room_number WHERE".$sj1 .$sj2 .$sj3 .$sj6 .$sj7 .$sj8 .$sj4 .$sj5 .$sj11;
                $data_dorm_roominfor_total = $this->db->query($sql_total, $sj1, $sj2, $sj3, $sj6, $sj7, $sj8, $sj4, $sj5, $sj11);
            }
            else
            {   
                $sj8 = "AND A.remainNumber > 0 AND A.peopleNumber > 0";
                $sj9 = "ORDER BY A.remainNumber";
                $sql = "SELECT DISTINCT A.area_number, A.area_name, A.floor_number, A.floor_name, A.dorm_floor, A.room_number, A.remainNumber FROM dorm_roominfor AS A LEFT JOIN dorm_bed AS B ON A.area_number = B.area_number 
                        AND A.floor_number = B.floor_number AND A.dorm_floor = B.dorm_floor AND A.room_number = B.room_number WHERE".$sj1 .$sj2 .$sj3 .$sj6 .$sj7 .$sj8 .$sj4 .$sj5 .$sj11 .$sj9 .$sj10; 
                $data_dorm_roominfor = $this->db->query($sql, $sj1, $sj2, $sj3, $sj6, $sj7, $sj8, $sj4, $sj5, $sj9, $sj10);

                $sql_total = "SELECT DISTINCT A.area_number, A.area_name, A.floor_number, A.floor_name, A.dorm_floor, A.room_number, A.remainNumber FROM dorm_roominfor AS A LEFT JOIN dorm_bed AS B ON A.area_number = B.area_number 
                             AND A.floor_number = B.floor_number AND A.dorm_floor = B.dorm_floor AND A.room_number = B.room_number WHERE".$sj1 .$sj2 .$sj3 .$sj6 .$sj7 .$sj8 .$sj4 .$sj5 .$sj11 .$sj9; 
                $data_dorm_roominfor_total = $this->db->query($sql_total, $sj1, $sj2, $sj3, $sj6, $sj7, $sj8, $sj4, $sj5, $sj11, $sj9);
            }  
            
            $totalPage = count($data_dorm_roominfor_total->result());
                                    
            if($data_dorm_roominfor->num_rows()>0)
            {
                $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $data_dorm_roominfor->result(), 'totalpage' => $totalPage);
                $result = json_encode($return_su);
            }
            else
            {
                $return_fa = array('res' => '40001', 'msg' => '查询无数据', 'data' => '', 'totalpage' => '');
                $result = json_encode($return_fa);
            }
            
            return $result;
        }


        /**
         * @description:入住筛选界面方法:取床位与柜子 
         * @param {area_number, floor_number, dorm_floor, room_number}
         * @return {*}
         */        
        public function check_condition_bed_table($area_number, $floor_number, $dorm_floor, $room_number)
        {
            if ($area_number == '' | $floor_number == '' || $dorm_floor == '' | $room_number == '') 
            {
                $return = array('res' => '40002', 'msg' => '请输入必填字段' ,'data' => '');
                $result = json_encode($return);
            } 
            else 
            {
                $where = array('area_number' => $area_number, 'floor_number' => $floor_number, 'dorm_floor' => $dorm_floor, 'room_number' => $room_number, 'bedStatus' => 1, 'check_inWhether' => 0);
                //取床位
                $this->db->select('bedNumber');
                $this->db->where($where);
                $query = $this->db->get('dorm_bed');
                //取宿舍在用的柜子号
                // $this->db->select('RY_wardrobe');
                // $this->db->where($where);
                // $query1 = $this->db->get('dorm_wardrobe');
                // if($query->num_rows()>0 && $query1->num_rows()>0)
                // print_r($this->db->last_query());
                // exit;
                if ($query->num_rows() > 0) 
                {
                    $return_su = array('res' => '40000', 'msg' => '查询成功', 'data' => $query->result());
                    $result = json_encode($return_su);
                } 
                else 
                {
                    $return_fa = array('res' => '40001', 'msg' => '查询无数据' ,'data' => '');
                    $result = json_encode($return_fa);
                }
            }
            return $result;
        }
}
